package com.linkoog.devtools.dubbo.toolwindow.environment;

import com.intellij.openapi.project.Project;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.table.TableModelEditor;

import javax.swing.*;
import java.awt.*;

public class DubboTestEnvironmentPanel {

    private Project project;
    private JPanel myMainPanel;

    private DubboEnvironmentTableEditer myEditer;


    public DubboTestEnvironmentPanel(Project project) {
        this.project = project;
        this.myEditer = new DubboEnvironmentTableEditer();
        myMainPanel.add(myEditer.createComponent(), BorderLayout.CENTER);
    }


    private void initTable() {

    }

    public JPanel getMyMainPanel() {
        return myMainPanel;
    }

    private static final ColumnInfo[] COLUMNS = {
            new TableModelEditor.EditableColumnInfo<DubboEnvironment, String>("name") {
                @Override
                public String valueOf(DubboEnvironment item) {
                    return item.getName();
                }

                @Override
                public void setValue(DubboEnvironment item, String value) {
                    item.setName(value);
                }

                @Override
                public boolean isCellEditable(DubboEnvironment item) {
                    return false;
                }
            },
            new TableModelEditor.EditableColumnInfo<DubboEnvironment, String>("Address") {
                @Override
                public String valueOf(DubboEnvironment item) {
                    return item.getProtocol() + "://" + item.getIp() + ":" + item.getPort();
                }

                @Override
                public boolean isCellEditable(DubboEnvironment item) {
                    return false;
                }
            },
            new TableModelEditor.EditableColumnInfo<DubboEnvironment, String>("Version") {
                @Override
                public String valueOf(DubboEnvironment item) {
                    return item.getVersion();
                }

                @Override
                public void setValue(DubboEnvironment item, String value) {
                    item.setVersion(value);
                }

                @Override
                public boolean isCellEditable(DubboEnvironment item) {
                    return false;
                }
            },
            new TableModelEditor.EditableColumnInfo<DubboEnvironment, String>("Group") {
                @Override
                public String valueOf(DubboEnvironment item) {
                    return item.getGroup();
                }

                @Override
                public void setValue(DubboEnvironment item, String value) {
                    item.setGroup(value);
                }

                @Override
                public boolean isCellEditable(DubboEnvironment item) {
                    return false;
                }
            }};
}
